<div>
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <header class="panel-heading">
                    <a class="btn btn-default" href="/setting/privilege-create">新增角色</a>
                </header>
            </div>
            <div class="panel-body">
                <form class="form-horizontal adminex-form">
                    <div class="form-group">
                        <label class="col-sm-1 col-sm-1 control-label">选择角色</label>
                        <div class="col-sm-1">
                            <select class="select-option col-lg-12 select-opacity selectEdit" name="role" id="role">
                                <option value="">管理员</option>
                                <option value="">业务员</option>
                            </select>
                        </div>
                        <label href="" data-toggle="modal" id="privilege_name" onclick="javascript:privilege_name(this);return false;" style="margin-top:8px;"><i class="fa fa-edit"></i>修改角色名称</label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 col-sm-1 control-label"></label>
                        <label class="col-sm-4">说明：<br>
                            1、具备该角色的用户登录后会显示相对应的可操作模块；<br>
                            2、修改角色权限后，所有赋予此角色的员工账号对应权限均将修改；<br>
                            3、管理员不可修改名称，权限；配送司机，业务员不可修改名称。<br></label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label">角色权限明细</label>
                        <label class="control-label">
                            <input type="checkbox" name="all">全选
                        </label>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 col-sm-1 control-label"></label>
                        <table class="table table-bordered">
                            <tbody>
    <!--                        --><?php //if($this->privilege_list){foreach ($this->privilege_list as $v) { ?>
    <!--                            <tr>-->
    <!--                                <td class="col-sm-1 text-left"></td>-->
    <!--                                <td class="col-sm-1 text-left" style="background-color: #E7E8EA;" >-->
    <!--                                    <input class="privilege_all" type="checkbox" name="privilege_name" data="--><?php //echo $v->getId();?><!--">--><?php //echo $v->getName(); ?><!--</td>-->
    <!--                                <td class="col-sm-10" style="overflow: inherit;">-->
    <!--                                    <div class="col-sm-3" hidden>-->
    <!--                                        <div class="checkbox text-left">-->
    <!--                                            <label>-->
    <!--                                                <input type="checkbox" name="privilege" parent="--><?php //echo $v->getId();?><!--" class="privilege_all --><?php //echo $v->getId();?><!--" data="--><?php //echo $v->getId(); ?><!--">--><?php //echo $v->getName(); ?>
    <!--                                            </label>-->
    <!--                                        </div>-->
    <!--                                    </div>-->
    <!--                                    --><?php //if($v->getList()){foreach ($v->getList() as $m) { ?>
    <!--                                        <div class="col-sm-3">-->
    <!--                                            <div class="checkbox text-left">-->
    <!--                                                <label >-->
    <!--                                                    <input type="checkbox" name="privilege" parent="--><?php //echo $v->getId();?><!--" class="privilege_all --><?php //echo $v->getId();?><!--" data="--><?php //echo $m->getId(); ?><!--">--><?php //echo $m->getName(); ?>
    <!--                                                    --><?php //if($m->getList()){ $name = array();foreach ($m->getList() as $c){array_push($name,'</br>'.$c->getName());} ?>
    <!--                                                        <p style="display: inline;" class="tooltip-options" >-->
    <!--                                                            <a href="#" class="tooltip-a"  style="text-align: left;"  data-placement="right" data-toggle="tooltip" title="包含以下权限:--><?php //echo implode(',',$name);?><!--" >-->
    <!--                                                                <img width="17px" height="17px" id="mo" src="/assets/images/tishi_moren.png" onmousemove="this.src='/assets/images/tishi_jingguo.png'" onmouseout="this.src='/assets/images/tishi_moren.png'" class="piliang"/>-->
    <!--                                                            </a>-->
    <!--                                                        </p>-->
    <!--                                                    --><?php //} ?>
    <!--                                                </label>-->
    <!--                                            </div>-->
    <!--                                        </div>-->
    <!--                                        --><?php //if($m->getList()){foreach ($m->getList() as $t){?>
    <!--                                            <div class="col-sm-3" hidden>-->
    <!--                                                <div class="checkbox text-left">-->
    <!--                                                    <label >-->
    <!--                                                        <input type="checkbox" name="privilege" class="privilege_all --><?php //echo $v->getId();?><!-- --><?php //echo $m->getId();?><!-- --><?php //echo $t->getId();?><!--" data="--><?php //echo $t->getId(); ?><!--">--><?php //echo $t->getName(); ?>
    <!--                                                    </label>-->
    <!--                                                </div>-->
    <!--                                            </div>-->
    <!--                                        --><?php //}} ?>
    <!--                                    --><?php //}} ?>
    <!---->
    <!--                                </td>-->
    <!--                            </tr>-->
    <!--                        --><?php //}} ?>
                            </tbody>
                        </table>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-1 col-sm-1 control-label">&nbsp;</label>
                        <div class="col-sm-12 button_quan" style="position: fixed;bottom: 3%;left: 10%;background-color: white;">
                            <button type="button" class="btn btn-default submit" id="rename">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal" class="modal fade"
     style="display: none;">
    <div class="modal-dialog" style="width: 40%">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">修改角色名称</h4>
            </div>
            <div class="modal-body" id="con_box">
                <form class="form-horizontal adminex-form">
                    <div class="form-group">
                        <label class="col-sm-1 col-sm-1 control-label">角色名称</label>
                        <div class="col-sm-8">
                            <input class="form-control" type="text" id="role_name">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" onclick="javascript:rename(this);return false;">提交</button>
            </div>
        </div>
    </div>
</div>
<!--<script type="text/javascript">
    $(function () { $(".tooltip-options a").tooltip({html : true });});
    //
    $("input[name=all]").click(function(){
        if(this.checked){
            $("[name='privilege']").each(function(){
                $(this).prop('checked',true);
            })
            $("[name='privilege_name']").each(function(){
                $(this).prop('checked',true);
            })
        }else{
            $("[name='privilege']").each(function(){
                $(this).prop('checked',false);
            })
            $("[name='privilege_name']").each(function(){
                $(this).prop('checked',false);
            })
        }
    });

    $("input[name=privilege_name]").click(function(){
        var data = $(this).attr('data');
        if(this.checked){
            $("."+data).each(function(){
                $(this).prop('checked',true);
            })
        }else{
            $("."+data).each(function(){
                $(this).prop('checked',false);
            })
        }
    });

    $("input[name=privilege]").click(function(){
        var data = $(this).attr('data');
        if(this.checked){
            $("."+data).each(function(){
                $(this).prop('checked',true);
            })
            var parent = $(this).attr('parent');
            $("input[name=privilege_name]").each(function(index,el){
                if($(el).attr('data') == parent){
                    $(el).prop('checked',true);
                }

            });
            $("."+parent).each(function(index,el){
                if($(el).attr('data')== parent){
                    $(el).prop('checked',true);
                }

            })
        }else{
            $("."+data).each(function(){
                $(this).prop('checked',false);
            })
            var parent = $(this).attr('parent');
            var m = 0;
            $("."+parent).each(function(index,el){
                if($(el).attr('data')!=parent && this.checked){
                    m = 1;
                }
            })
            if(m == 0){
                $("input[name=privilege_name]").each(function(index,el){
                    if($(el).attr('data') == parent){
                        $(el).prop('checked',false);
                    }

                });
                $("."+parent).each(function(index,el){
                    if($(el).attr('data')== parent){
                        $(el).prop('checked',false);
                    }
                })
            }

        }

    });

    document.ready = function () {
        var role_id = $('#role').find("option:selected").val();
        getroleprivilege(role_id);
    }
    function privilege_name(el){
        var rename = $('#role').find("option:selected").attr('rename');
        if(rename == '<?php /*echo \Cls\Role\Role::CAN_MODIFY_NAME_NO */?>'){
            layer.msg('此角色名称不能修改');
            return false;
        }
    }
    //修改名字
    function rename(el){
        var role_name = $("#role_name").val();
        if(role_name == ''){
            layer.msg('名称不能为空');
            return false;
        }
        var role_id = $("#role").val();
        $.ajax({
            type:'post',
            url:'/staff/rolesave',
            data:{
                type:'update_name',
                role_id:role_id,
                role_name:role_name,
            },
            dataType:'json',
            success:function(response){
                if(response.code == 200){
                    layer.alert(response.message);
                    setTimeout(window.location.href = '/staff/role',1000);
                }else{
                    layer.alert(response.message);
                }
            }
        });
    }

    // 角色权限
    $('#role').change(function () {
        var role_id = $(this).val();
        var role_name = $('#role').find("option:selected").attr('role_name');
        var rename = $('#role').find("option:selected").attr('rename');
        if(rename != '<?php /*echo \Cls\Role\Role::CAN_MODIFY_NAME_NO */?>'){
            $("#privilege_name").attr('href','#myModal');
            $("#privilege_name").attr('onclick','');
        }else{
            $("#privilege_name").attr('href','');
            $("#privilege_name").attr('onclick','javascript:privilege_name(this);return false;');
        }
        $(".privilege_all").each(function(index,el){
            $(el).attr('checked',false);
        })
        $("#role_name").val(role_name);
        getroleprivilege(role_id);
    });

    function getroleprivilege(role_id){
        if (role_id) {
            $.ajax({
                type:'post',
                url:'/staff/rolesave',
                data:{
                    type:'get_role_privilege',
                    role_id:role_id,
                },
                dataType:'json',
                success:function(response){
                    if(response.code == 200){
                        var result = response.result;
                        //for(var i=0;i<result.length;i++){
                        $(".privilege_all").each(function(index,el){
                            if($.inArray($(el).attr('data'),result) >= 0){
                                $(el).attr('checked',true);
                            }
                        })
                        //}
                        $("input[name=all]").prop('checked',false);
                        var m = 1;
                        $(".privilege_all").each(function(index,el){
                            if(!this.checked){
                                m = 0;
                            }
                        })

                        if(m == 1){
                            $("input[name=all]").prop('checked',true);
                        }else{
                            $("input[name=all]").prop('checked',false);
                        }

                    }
                }
            });
        }
    }

    // 提交权限表单
    $('.submit').click(function () {
        var role_id = $("#role").val();
        var is_role = $('#role').find("option:selected").attr('is_role');
        if(is_role == '<?php /*echo \Cls\Role\Role::CAN_MODIFY_NAME_NO */?>'){
            layer.msg('此角色权限不能修改');
            return false;
        }

        var privilege =[];
        $("[name='privilege']:checked").each(function(index,el){
            privilege.push($(el).attr('data'));
        })
        if(privilege.length == 0){
            layer.msg('请选择权限');
            return false;
        }
        var index = layer.msg('保存中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:1000000});
        // 提交表单
        $.ajax({
            type:'post',
            url:'/staff/rolesave',
            data:{
                type:'save',
                role_id:role_id,
                privilege:privilege.join(','),
            },
            dataType:'json',
            success:function(response){
                if (response.code == 200) {
                    layer.close(index);
                    layer.alert(response.message);
                    setTimeout(window.location.href = '/staff/role',1000);
                } else {
                    layer.close(index);
                    layer.alert(response.message);
                }
            }
        });
    });

</script>-->